#ifndef _MERGE_H__
#define _MERGE_H__
#include <string>
using namespace std;
#include <proc/connection.h>
#include "tableschema.h"
#include "partition.h"

class Merge
{
public:
	Merge(Connection &connection, const TableSchema &tableSchema, const string &branchId, const string &logicDate, int parallels, const string &join, int method, Partition &partition, int delFlag, int truncateFlag);
	
	int merge();
	
private:
	int mergePartition(const string &partitionName);
	int prepareMergePartitionSql(const string &partitionName);
	
	int getPartitionName();
	int prepareMergeSql();
	int truncate();
	int deleteTable();
	int append();

	int deleteInsert();

private:
	Connection &connection;
	const TableSchema &tableSchema;
	Partition &partition;
	
	string branchId;
	string logicDate;
	string join;
	
	int parallels;
	int method;
	int delFlag;
	int truncateFlag;
	
	string partitionName;
	string mergeSql;
};

#endif
